package ext.acae2.object.forms;

import java.util.List;

import wt.doc.WTDocument;
import wt.util.WTException;
import wt.vc.Iterated;

import com.ptc.core.components.beans.ObjectBean;
import com.ptc.core.components.forms.DefaultObjectFormProcessor;
import com.ptc.core.components.forms.FormResult;
import com.ptc.netmarkets.model.NmOid;
import com.ptc.netmarkets.util.beans.NmCommandBean;
import com.ptc.windchill.enterprise.object.util.ReIdentifyHelper;

import ext.acae2.object.helper.ObjectIdentifiedHelper;

/**
 * @desription 重命名processes
 * @author cnie
 * @date 2013-7-25 下午12:50:44
 */
public class ExtRenameObjectFormProcessor extends DefaultObjectFormProcessor{

	@Override
	public FormResult doOperation(NmCommandBean nmcommandbean,
			List<ObjectBean> list) throws WTException {
		NmOid nmoid = nmcommandbean.getElementOid();
		if(nmoid ==null){
			nmoid = nmcommandbean.getActionOid();
		}
		if(nmoid==null){
			nmoid = nmcommandbean.getPrimaryOid();
		}
		Object obj = nmoid.getWtRef().getObject();
		String newName = ReIdentifyHelper.getSelectedTextBoxValueFromForm(nmcommandbean, "name");
		if(obj instanceof WTDocument){
			WTDocument doc  = (WTDocument)obj;
			ObjectIdentifiedHelper.changeWTDocumentIdentity(doc, newName, null);
		}
		FormResult formResult =  super.doOperation(nmcommandbean, list);
		return formResult;
	}

}
